package com.dk.controller;

import com.dk.pojo.TabMenu;
import com.dk.service.MenuService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.omg.CORBA.INTERNAL;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.dc.pr.PRError;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    //        展示菜单
    @RequestMapping("Tree")
    @ResponseBody
    public List<Map<String, Object>> Tree() {
        List<Map<String, Object>> list = menuService.selectInfo();
        return list;

    }

    @RequestMapping("toshow")
    public String toshow() {
        return "menu/show";
    }

    @RequestMapping("ztreeInfo")
    @ResponseBody
    public List<Map<String, Object>> ztreeInfo() {
        List<Map<String, Object>> list = menuService.selectztreeInfo();
        return list;
    }

    @RequestMapping("addInfo")
    public String addInfo() {
        return "menu/add";

    }

    @RequestMapping("insertinto")
    @ResponseBody
    public boolean insertinto(TabMenu t) {
        boolean a = menuService.insertinto(t);
        return a;
    }

    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id") Integer id, Model mo) {
        TabMenu a = menuService.selectByid(id);
        mo.addAttribute("m", a);
        return "menu/update";
    }

    //        修改
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TabMenu t) {
        boolean a = menuService.updateInfo(t);
        return a;
    }

    @RequestMapping("deleteInfo/{id}")
    @ResponseBody
    public boolean deleteInfo(@PathVariable("id") Integer id) {
        boolean a = menuService.deleteInfo(id);
        return a;
    }

    @RequestMapping("getztreeInfo/{rid}")
    @ResponseBody
    public List<Map<String, Object>> getztreeInfo(@PathVariable("rid") Integer rid) {
        List<Map<String, Object>> list = menuService.getztreeInfo(rid);
        return list;
    }
}
